define(['app'], function(app) {
	'use strict';

	// 实例化方法
	var factory = function(Http) {
		function get_data_panicbuy_dealer(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"region":[{"region_id":"001","region_name":"江苏","is_all":false,"store":[{"store_id":"001","store_name":"世达"},{"store_id":"002","store_name":"博士"}]},{"region_id":"002","region_name":"浙江","is_all":true,"store":[{"store_id":"003","store_name":"益达"},{"store_id":"004","store_name":"飞达"}]}],"goods":[{"goods_id":"001","goods_name":"一字螺丝刀","promotion_price":10,"limit_buy_num":10,"count":200},{"goods_id":"002","goods_name":"十字螺丝刀","promotion_price":10,"count":1000,"limit_buy_num":10}],"change_price":false},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_panicbuy_member(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"region":[{"region_id":"001","region_name":"江苏","is_all":false,"member":[{"member_id":"001","member_name":"益达"},{"member_id":"002","member_name":"博士"}]},{"region_id":"002","region_name":"上海","is_all":true,"member":[{"member_id":"003","member_name":"飞达"},{"member_id":"004","member_name":"柏飞"}]}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_friends_list(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"member": [' +
					'{"member_id": "001","name": "Mary","mobile": "18912345678"},' +
					'{"member_id": "002","name": "Jane","mobile": "18912345678"}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_panicbuy_detail(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"act_id":"001","name":"促销","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","create_group":true,"has_packets":true,"image":[{"id":"001","image":"img/upload/pro-img01.jpg"},{"id":"002","image":"img/upload/pro-img01.jpg"}],"brand_id":"001","cat_type":[{"id":"001","name":"手动工具"},{"id":"002","name":"电动工具"}],"brand_name":"英勇"},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		function get_data_goods_list(result){
			if(HTTP_ISLOGIC){
				result = '{"success":true,"msg":"","result":{"store_count":"500","data":[{"goods_id":1,"name":"十字螺丝刀","introduce":"十字螺丝刀","price":5.5,"mktprice":8,"preprice":5.5,"store_id":"WuJin_1","store_name":"五金一店","image":"img/upload/pro-img01.jpg","storenumber":100,"salenumber":20,"personlimit":3,"qq":"1234567","phone":"18912345678"},{"goods_id":2,"name":"一字螺丝刀","introduce":"一字螺丝刀","price":5.5,"mktprice":8,"preprice":5.5,"store_id":"WuJin_1","store_name":"五金一店","image":"img/upload/pro-img01.jpg","storenumber":80,"salenumber":10,"personlimit":3,"qq":"1234567","phone":"18912345678"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else 
			return result;
		}
		function get_data_dealer_jion(result){
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"act_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		// 返回信息
		return {

			get_grabseckill: function(callback) {

				var data = new Object();

				data.goods = [{
					name: '商品1',
					price: '1200',
					order: '200',
					number: '100',
					start: '3'
				}, {
					name: '商品1',
					price: '1200',
					order: '200',
					number: '100',
					start: '3'
				}, {
					name: '商品1',
					price: '1200',
					order: '200',
					number: '100',
					start: '3'
				}, {
					name: '商品1',
					price: '1200',
					order: '200',
					number: '100',
					start: '3'
				}, {
					name: '商品1',
					price: '1200',
					order: '200',
					number: '100',
					start: '3'
				}];

				data.group_price = [{
					name: '1800件5天2100',
					price: '1800',
					operate: '删除'
				}, {
					name: '1800件5天2100',
					price: '1800',
					operate: '增加档次'
				}, {
					name: '1800件5天2100',
					price: '1800',
					operate: '删除'
				}, {
					name: '1800件5天2100',
					price: '1800',
					operate: '删除'
				}, {
					name: '1800件5天2100',
					price: '1800',
					operate: '删除'
				}];

				data.group_saleman = [{
					name: '经销商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '经销商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '经销商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '经销商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '经销商1',
					id: "1",
					img: 'group_saleman.png'
				}];
				data.group_agency = [{
					name: '代理商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '代理商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '代理商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '代理商1',
					id: "1",
					img: 'group_saleman.png'
				}, {
					name: '代理商1',
					id: "1",
					img: 'group_saleman.png'
				}];
				// 函数回调
				if(callback)
					callback(data);

			},
			panicbuy_dealer: function(act_id, callback) {
				Http.post({
					method: 'marketing.panicbuy.dealer',
					act_id: act_id
				}, function(result) {
					if(callback)
						callback(get_data_panicbuy_dealer(result).result);
				}, function(e) {

				}, function() {

				})
			},
			panicbuy_member: function(act_id, callback) {
				Http.post({
					method: 'marketing.panicbuy.member',
					act_id: act_id
				}, function(result) {
					if(callback)
						callback(get_data_panicbuy_member(result).result);
				}, function(e) {

				}, function() {

				})
			},
			friends_list: function(region,member,callback) {
				Http.post({
					method: 'member.friends.getlist',
					pagelimit: 8,
					nPage: 1,
					show_count: 5,
					region:region,
					member:member
				}, function(result) {
					if(callback)
						callback(get_data_friends_list(result).result);
				}, function(e) {

				}, function() {

				})
			},
			panicbuy_detail: function(act_id, callback) {
				Http.post({
					method: 'marketing.panicbuy.detail',
					act_id: act_id
				}, function(result) {
					if(callback)
						callback(get_data_panicbuy_detail(result).result);
				}, function(e) {

				}, function() {

				})
			},
			dealer_jion:function(act_id,region,callback){
				var updateParams = new Object();
				updateParams.act_id = act_id;
				updateParams.region = region;
				updateParams = JSON.stringify(updateParams);
				Http.post({
					method:'marketing.panicbuy.dealerjion',
					updateParams:updateParams
				},function(result){
					if(callback)
					callback(get_data_dealer_jion(result));
							
				},function(e){
					
				},function(){
					
				})
			},
			goods_list:function(act_id,callback){
				Http.post({
					method:'goods.search.getlist',
					cat_type:14,
					act_id:act_id
				},function(result){
					if(callback)
					callback(get_data_goods_list(result).result);
				},function(e){
					
				},function(){
					
				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Grabseckill", factory);
});